//============================================================================
//
//  Buffer.h
//  
//  Created By Jeromy Stroh 2009
//
//  Converted to use DXUT and DirectX 9/11 compatibility by David Teeder 2010
//
//============================================================================
#pragma once

namespace d3d11
{
	class Buffer
	{
	public:
		enum Type
		{	
			UNSPECIFIED,
			D3D9INDEX,
			D3D9VERTEX,
			D3D11INDEX,
			D3D11VERTEX,
			D3D11CONSTANT,
		};

	public:
		Buffer(D3D11_USAGE usage, uint stride, uint dataSize, void *initData ); // Vertex Buffer 11
		Buffer(D3D11_USAGE usage, uint dataSize, DXGI_FORMAT index_format, UINT uiNumVertices, void *initData = NULL); // Index Buffer 11
		Buffer(DWORD vertex_format, DWORD usage, D3DPOOL pool, uint stride, uint dataSize, void *initData = NULL); // Vertex Buffer 9
		Buffer(D3DFORMAT index_format, DWORD usage, D3DPOOL pool, uint uiIndexCount, uint dataSize, void *initData = NULL);	// Index Buffer 9
		Buffer(D3D11_USAGE usage, uint dataSize); // Constant Buffer 11
		~Buffer();

		void SetAsVertexBuffer();
		void SetAsIndexBuffer();

		ID3D11Buffer			*getBuffer()		const { return m_pBuffer; }
		ID3D11Buffer	* const *getBufferConst()   const { return &m_pBuffer; }
		IDirect3DVertexBuffer9	*getVertexBuffer9()	const { return m_pVertexBuffer9; }
		IDirect3DIndexBuffer9	*getIndexBuffer9()	const { return m_pIndexBuffer9; }
		DWORD					getFVF()			const { return m_fvf; }
		D3DFORMAT				getIndexFormat9()	const { return m_indexformat; }
		DXGI_FORMAT				getIndexFormat()	const { return m_indexFormat11; }
		UINT					getIndexCount()		const { return m_uiIndexCount; }

	private:
		Type					m_type;
		uint					m_stride;		// the size of each element of a buffer
		uint					m_dataSize;		// the number of bytes this buffer contains
		D3DFORMAT				m_indexformat;	// for directX 9 index buffers
		DXGI_FORMAT				m_indexFormat11;	
		DWORD					m_fvf;			// for directX 9 vertex buffers
		UINT					m_uiIndexCount; // number of items

		IDirect3DDevice9		*m_pD3DDevice9;
		ID3D11Device			*m_pD3DDevice11;

		ID3D11Buffer			*m_pBuffer;
		IDirect3DVertexBuffer9	*m_pVertexBuffer9;
		IDirect3DIndexBuffer9	*m_pIndexBuffer9;
	};
}
